import { Body, Controller, Post } from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiSecurity, ApiTags } from '@nestjs/swagger';
import { ADMIN_PREFIX } from '../../admin.constants';
import { SysOperationLogService } from './operationLog.service';
import { AdminUser } from '../../core/decorators/admin-user.decorator';

@ApiSecurity(ADMIN_PREFIX)
@ApiTags('操作日志模块')
@Controller('operationLog')
export class SysOperationLogController {
  constructor(private operationLogService: SysOperationLogService) {}

  @ApiOperation({ summary: '分页获取获取操作日志列表' })
  @ApiOkResponse()
  @Post('page')
  async page(@Body() dto) {
    const [list, total] = await this.operationLogService.page(dto);

    return {
      list,
      pagination: {
        total,
        pageNum: dto.pageNum,
        pageSize: dto.pageSize,
      },
    };
  }

  @ApiOperation({ summary: '添加操作日志' })
  @ApiOkResponse()
  @Post('add')
  async add(@Body() dto, @AdminUser() user) {

    await this.operationLogService.add(dto, user);
  }

  @ApiOperation({ summary: '删除操作日志' })
  @ApiOkResponse()
  @Post('delete')
  async delete(@Body() dto) {
    await this.operationLogService.delete(dto);
  }
}
